package org.club.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.club.common.WebSocket.WebSocketMessage;
import org.club.common.model.dto.Announcemen;
import org.club.common.model.dto.AnnouncementsDto;
import org.club.common.model.entity.Announcement;
import org.club.common.model.vo.AnnouncementUserVO;
import org.club.common.model.vo.AnnouncementVO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface AnnouncementMapper {

//    获取所有公告以及创建者的账号
    List<AnnouncementVO> getAllAnnouncements(AnnouncementsDto announcementsDto);
//    根据id获取公告
    @Select("select * from announcements where id=#{id}")
    Announcement selectById(Long id);
    int updateById(Announcement announcement);
//    根据id删除公告
    @Select("delete from announcements where id=#{id}")
    void deleteAnnouncement(Long id);
    /**
     * 创建公告并发送
     * @param message WebSocket消息
     * @return 公告ID
     */
    Long createAnnouncement(WebSocketMessage message);

    /**
     * 创建公告用户关联
     * @param announcementId 公告ID
     * @param userId 用户ID
     * @return 影响行数
     */
    int createAnnouncementUser(@Param("announcementId") Long announcementId, @Param("userId") Long userId);
//    根据关键字搜索用户
    List<AnnouncementUserVO> searchUsers(@Param("keyword") String keyword);
//    创建公告
    Integer createANnouncements(Announcemen announcemen);
//查询公告是否存在
    @Select("select COUNT(*) from announcements where id=#{id}")
    Integer selectannouncements(Long id);
//更新公告的状态
    @Select("update announcements set status=1 where id=#{id}")
    Integer updateannouncementsId(Long id);
//    根据用户ID获取用户名
    @Select("select username from users where id= #{userId}")
    String getUsernameById(@Param("userId") Long userId);
//    更新公告的状态
    @Update("UPDATE announcements SET publish_status = #{status} WHERE id = #{id}")
    int updateAnnouncementStatus(@Param("id") Long id, @Param("status") String status);
//    获取所有用户ID
    @Select("SELECT id FROM users")
    List<Long> getUserIdCondition();
}
